﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebControls;
using Slam.FieldTypes;

namespace SlamCms.SharePoint.FieldTypes
{
	public partial class FixedValueFieldEditor : UserControl, IFieldEditor
	{	
		private string fixedValue;

		#region IFieldEditor Members

		public bool DisplayAsNewSection
		{
			get { return true; }
		}

		protected override void CreateChildControls()
		{
			base.CreateChildControls();

			txtFixedValue.Text = fixedValue;
		}

		public void InitializeWithField(Microsoft.SharePoint.SPField field)
		{
            SlamField fixedValueField = field as SlamField;
			if (fixedValueField != null)
			{
				fixedValue = (string)fixedValueField.GetCustomPropertyValue("FixedValue");
			}
		}

		public void OnSaveChange(Microsoft.SharePoint.SPField field, bool isNewField)
		{
			fixedValue = txtFixedValue.Text;

            SlamField fixedValueField = field as SlamField;

		    fixedValueField.SetCustomProperty("FixedValue", typeof (string), fixedValue);
		}

		#endregion

	}
}
